﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        //下标偶数
        static void Main(string[] args)
        {
            string[] arr = new string[5];
            arr[0] = "hhh";
            arr[1] = "123";
            arr[2] = "456";
            arr[3] = "aaa";
            arr[4] = "bbb";
            for (int i = 0; i < arr.GetLength(0); i++)
            {
               
                if (i%2==0)
                {   
                    Console.Write("[");
                    Console.Write(arr[i]);
                    Console.Write("]");
                    Console.WriteLine();
                }
                
            }

            //Test5();
            //Test4();
            //Test3();
            //Test2();
            //Test1();
            //Test();
        }

        //用户输入正方形边长，用*打印出实心正方形。
        public static void Test()
        {
            Console.WriteLine("请输入正方形的边长");
            int a = int.Parse(Console.ReadLine());
            string[,] arr = new string[a, a];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    arr[i, j] = "*";
                }

            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j] + " ");
                }
                Console.WriteLine("  ");
            }
            //Console.WriteLine("请输入正方形边长");
            //int a = int.Parse(Console.ReadLine());
            //for (int i = 0; i < a; i++)
            //{
            //    for (int j = 0; j <a; j++)
            //    {
            //        Console.Write("* ");
            //    }
            //    Console.WriteLine(" ");
            //}
        }
        //九九乘法表
        public static void Test1()
        {
            string[,] arr = new string[9, 9];
           
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    Console.Write((i + 1) + "*" + (j + 1) + "=" + (i + 1) * (j + 1) + "\t");
                }
                Console.WriteLine("");
            }

            //    for (int i = 1; i <=9; i++)
            //    {
            //        for (int j = 1; j <= i; j++)
            //        {
            //            Console.Write(i+"*"+j+"="+i*j+" ");
            //        }
            //        Console.WriteLine(" ");
            //    }
        }
        //用户输入正方形边长，用*打印出空心正方形。
        public static void Test2()
        {
            Console.WriteLine("请输入正方形的长");
            int a = int.Parse(Console.ReadLine());
            string[,] arr = new string[a, a];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if ((i == 0 || j == a - 1) || (j == 0 || i == a - 1))
                    {
                        arr[i, j] = "*";
                    }

                    else
                    {
                        arr[i, j] = " ";
                    }

                }

            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j] + " ");
                }
                Console.WriteLine("");
            }
        }
        //打印菱形
        public static void Test3()
        {
            Console.WriteLine("请输入菱形的长");
            int a = int.Parse(Console.ReadLine());
            string[,] arr = new string[2*a-1, 2*a-1];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (i==0)
                    {
                        if (j==a-1)
                        {
                            arr[i, j] = "*";
                        }
                        else
                        {
                            arr[i, j] = " ";
                        }
                    }
                    else if (i<=a-1)
                    {
                        if (j<=a-1+i&&j>=a-1-i)
                        {
                            arr[i, j] = "*";
                           
                        }
                        else
                        {
                            arr[i, j] = " ";
                        }
                    }
                    else
                    {
                        if (j>=i-a+1&&j<=3*a-3-i)
                        {
                            arr[i, j] = "*";
                        }
                        else
                        {
                            arr[i, j] = " ";
                        }
                    }
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j] + "");
                   
                }
                Console.WriteLine("");
            }
        }
        //杨辉三角
        public static void Test4() {
            int[,] arr = new int[10,10];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (j==0)
                    {
                        arr[i, 0] =1;
                    }
                    else if (i==j)
                    {
                        arr[i, j] = 1;
                    }
                    else if (i>=j)
                    {
                         arr[i, j] = arr[i-1, j - 1] + arr[i-1, j];
                    }
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (arr[i,j]!=0)
                    {
                    Console.Write(arr[i, j] + "\t");
                    } 
                }
                Console.WriteLine();
            }
            

        }
        //数组排序
        public static void Test5() {
            Console.WriteLine("请输入一个数");
            int a=int.Parse(Console.ReadLine());
            int[] arr = new int[6];
            arr[0] = 45;
            arr[1] = 23;
            arr[2] = 34;
            arr[3] = 78;
            arr[4] = 88;
            arr[5] = a;
            foreach (var item in arr)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("排序前");
            Array.Sort(arr);
            Array.Reverse(arr);
            foreach (var item in arr)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("排序后");
        }


       
    }
}
